<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function dfs(data) {
            if (typeof data !== 'object' || !data) return data
            if (Array.isArray(data)) {
                return data.map(item => dfs(item))
            }

            let newObj = {}
            for (const key in data) {
                if (Object.prototype.hasOwnProperty.call(data, key)) {
                    let newKey = key.replace(/_([a-z])/g, res => {
                        console.log(`res-${res}`);
                        return res[1].toUpperCase()
                    })
                    newObj[newKey] = dfs(data[key])
                }
            }
            return newObj
        }
        /**
         * Object.prototype.hasOwnProperty.call 获取自身属性
         * see also:
         * 
         * Object.hasOwn()
         * Object.prototype.hasOwnProperty() 的替代品
         * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn#browser_compatibility
         * 
         * Object.keys()
         * 对象的自身可枚举属性组成的数组
         * https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
         * 
         * Object.getOwnPropertyNames()
         * 对象的所有自身属性的属性名（包括不可枚举属性但不包括 Symbol 值作为名称的属性）组成的数组
         * https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames
         * 
         * Object.getOwnPropertySymbols()
         * 给定对象自身的所有 Symbol 属性的数组。
         * https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols
         * 
         * Reflect.ownKeys()
         * 静态方法 Reflect.ownKeys() 返回一个由目标对象自身的属性键组成的数组，基本等同于 Object.getOwnPropertyNames() 与 Object.getOwnPropertySymbols 之和。
         * https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys
        */
        const data = {
            'ab_cd': 1,//abCd:1
            'bc_de': [
                {
                    'cb_ef': 1
                }
            ],
            // bcDe:[{
                // cbEf:1
            // }]
        }
        const res=dfs(data);
        console.log(res);
    </script>
</body>

</html>